package com.ruanyun.modular.admin.controller;

import cn.stylefeng.roses.core.util.ToolUtil;
import com.ruanyun.base.pojo.page.LayuiPageInfo;
import com.ruanyun.modular.admin.entity.TBasicinfo;
import com.ruanyun.modular.admin.model.params.TBasicinfoParam;
import com.ruanyun.modular.admin.model.result.TBasicinfoResult;
import com.ruanyun.modular.admin.service.TBasicinfoService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import com.ruanyun.sys.modular.system.model.result.CountyResult;
import com.ruanyun.sys.modular.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * 基本信息表控制器
 *
 * @author zs
 * @Date 2021-04-16 15:27:40
 */
@Controller
@RequestMapping("/tBasicinfo")
public class TBasicinfoController extends BaseController {

    private String PREFIX = "/tBasicinfo";

    @Autowired
    private TBasicinfoService tBasicinfoService;
    @Autowired
    private UserService userService;

    /**
     * 跳转到主页面
     *
     * @author zs
     * @Date 2021-04-16
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/tBasicinfo.html";
    }

    /**
     * 新增页面
     *
     * @author zs
     * @Date 2021-04-16
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/tBasicinfo_add.html";
    }

    /**
     * 编辑页面
     *
     * @author zs
     * @Date 2021-04-16
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/tBasicinfo_edit.html";
    }

    /**
     * 新增接口
     *
     * @author zs
     * @Date 2021-04-16
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(TBasicinfoParam tBasicinfoParam) {
        return this.tBasicinfoService.add(tBasicinfoParam);
    }

    /**
     * 编辑接口
     *
     * @author zs
     * @Date 2021-04-16
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(TBasicinfoParam tBasicinfoParam) {
        return this.tBasicinfoService.update(tBasicinfoParam);
    }

    /**
     * 删除接口
     *
     * @author zs
     * @Date 2021-04-16
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(TBasicinfoParam tBasicinfoParam) {
        return this.tBasicinfoService.updateDelFlagById((long)tBasicinfoParam.getId());
    }

    /**
     * 查看详情接口
     *
     * @author zs
     * @Date 2021-04-16
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(TBasicinfoParam tBasicinfoParam) {
        TBasicinfoResult detail = this.tBasicinfoService.getDetail(tBasicinfoParam.getId());

        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author zs
     * @Date 2021-04-16
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(TBasicinfoParam tBasicinfoParam) {
        return this.tBasicinfoService.findPageBySpec(tBasicinfoParam);
    }

    /**
     * 启用
     *
     * @author zs
     * @Date 2021-04-16
     */
    @ResponseBody
    @RequestMapping("/enable")
    public ResponseData enable(@RequestParam Long id) {
        return this.tBasicinfoService.enableById(id);
    }

    /**
     * 禁用
     *
     * @author zs
     * @Date 2021-04-16
     */
    @ResponseBody
    @RequestMapping("/disable")
    public ResponseData disable(@RequestParam Long id) {
        return this.tBasicinfoService.disableById(id);
    }

    /**
     * 查询列表
     *
     * @author zs
     * @Date 2021-04-16
     */
    @ResponseBody
    @RequestMapping("/basicList")
    public List<TBasicinfo> getList() {
        return this.tBasicinfoService.getList();
    }


    /*查询企业县区列表*/

    @ResponseBody
    @RequestMapping("/getCountyList")
    public List<CountyResult> getCountyList(){
        return  userService.getCountyList();
    }

}


